#! /bin/sh
#
# umountfs	Turn off swap and unmount all local filesystems.
#

PATH=/sbin:/bin:/usr/sbin:/usr/bin

echo "[umountfs] Deactivating swap..."
swapoff -a

# We leave /proc mounted.
echo "[umountfs] Unmounting local filesystems..."
grep -q /mnt/ram /proc/mounts && mount -o remount,ro /mnt/ram
mount -o remount,ro /

# sync to flush pending writes for loop-mounted file system.
sync

umount -f -a -r > /dev/null 2>&1

# Add an extra delay of 5 sec to make sure even a problematic HDD has enough time to go to park-position.
if [ "$RUNLEVEL" = "0" ]; then
  sdparm --command=stop /dev/sd?
  sleep 5
fi

echo "[umountfs] Good Bye..."

exit 0
